# 导入生成token模块
import jwt
# 导入时间模块
import time


# 生成token
def get_token(user):
    # 根据用户的id和手机号生成token
    payload = {
        "user_id": user["userId"],
        "phone": user["phone"],
        'userImg': user['userImg'],
        'nickname': user['nickName'],
        "exp": int(time.time()) + 3600  # 过期时间
    }
    # 生成token
    token = jwt.encode(payload, "jiajia o(╥﹏╥)o (*^▽^*)", algorithm="HS256")
    # 返回token
    return token


# 生成后台token
def get_admin_token(user):
    # 根据用户的id和手机号生成token
    payload = {
        "id": user["id"],
        'is_authority': user['is_authority'],
        'nickname': user['nickName'],
        "exp": int(time.time()) + 3600  # 过期时间
    }
    # 生成token
    token = jwt.encode(payload, "jiajia o(╥﹏╥)o (*^▽^*)", algorithm="HS256")
    # 返回token
    return token